import { Module, VuexModule, Mutation, Action, getModule } from 'vuex-module-decorators';
import store from '@/store';
import { SET_ALERT, CLOSE_ALERT } from '@/store/mutation-types';

@Module({ name: 'alert', store, dynamic: true })
class AlertStore extends VuexModule {
  show: boolean = false;
  message: string = '';
  title: string = '';
  btns: any = [];

  @Action({ commit: SET_ALERT })
  public alert(info: any) {
    return {
      message: info.message,
      title: info.title,
      btns: info.btns,
    };
  }
  @Mutation
  public [SET_ALERT](obj: any) {
    this.show = true;
    this.message = obj.message || '';
    this.title = obj.title || '';
    this.btns = obj.btns || [];
  }

  @Action({ commit: CLOSE_ALERT })
  closeAlert() {
    return;
  }

  @Mutation
  public [CLOSE_ALERT]() {
    this.show = false;
  }
}

export const alertStore = getModule(AlertStore);
